using System.Collections.Generic;
using UnityEditor;
using System.Linq;
public class MenuExtention
{
    const string LP_DEBUG = "LP_DEBUG";
    const string LP_RELEASE = "LP_RELEASE";
    static List<string> list = new List<string>();

    static void GetDefines()
    {
        string[] defines;
        PlayerSettings.GetScriptingDefineSymbolsForGroup(GetBuildTargetGroup(), out defines);
        list = defines.ToList<string>();
    }

    [MenuItem("GamePattern/Debug")]
    static void DebugPattern()
    {
        GetDefines();
        if (!list.Contains(LP_DEBUG))
        {
            list.Add(LP_DEBUG);
        }
        if (list.Contains(LP_RELEASE))
        {
            list.Remove(LP_RELEASE);
        }
        PlayerSettings.SetScriptingDefineSymbolsForGroup(GetBuildTargetGroup(), list.ToArray<string>());
    }

    [MenuItem("GamePattern/Debug", true)]
    static bool DebugPatternValidate()
    {
        GetDefines();
        return !list.Contains(LP_DEBUG);
    }

    [MenuItem("GamePattern/Release")]
    static void ReleasePattern()
    {
        GetDefines();
        if (!list.Contains(LP_RELEASE))
        {
            list.Add(LP_RELEASE);
        }
        if (list.Contains(LP_DEBUG))
        {
            list.Remove(LP_DEBUG);
        }
        PlayerSettings.SetScriptingDefineSymbolsForGroup(GetBuildTargetGroup(), list.ToArray<string>());
    }

    [MenuItem("GamePattern/Release", true)]
    static bool ReleasePatternValidate()
    {
        GetDefines();
        return !list.Contains(LP_RELEASE);
    }

    static BuildTargetGroup GetBuildTargetGroup()
    {
        BuildTargetGroup ret = BuildTargetGroup.Standalone;
#if UNITY_ANDROID
        ret = BuildTargetGroup.Android;
#elif UNITY_IOS
         ret = BuildTargetGroup.iOS;
#endif
        return ret;
    }
}
